package com.deyuanyun.pic.pipe.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.pipe.domain.MapTagging;
import com.deyuanyun.pic.pipe.domain.MapTaggingExample;
import com.deyuanyun.pic.pipe.mapper.MapTaggingMapper;
import com.deyuanyun.pic.pipe.service.MapTaggingService;
import com.deyuanyun.pic.settings.domain.util.DomainInitUtil;


@Service
public class MapTaggingServiceImpl implements MapTaggingService {

    private @Resource MapTaggingMapper mapTaggingMapper;
    
    @Override
    public List<MapTagging> queryMapTagging(String userId, String type) {
        
        MapTaggingExample example = new MapTaggingExample();
        example.createCriteria().andUserIdEqualTo(userId).andTypeEqualTo(type).andDeletedEqualTo((short)0);
        List<MapTagging> list = mapTaggingMapper.selectByExample(example);
        
        return list;
    }

    @Override
    public int createOrUpdate(MapTagging mapTagging) {
        
        int r;
        String mtid = mapTagging.getId();
        if(StringUtils.isEmpty(mtid)){
            DomainInitUtil.initCreateDomain(mapTagging);
            r = mapTaggingMapper.insertSelective(mapTagging);
            mtid = mapTagging.getId();
        }else{
            r = mapTaggingMapper.updateByPrimaryKeySelective(mapTagging);
        }
        
        return r;
    }

    @Override
    public int updateToDelete(String mtid) {
        
        MapTagging mapTagging = new MapTagging();
        mapTagging.setId(mtid);
        mapTagging.setDeleted((short)1);
        DomainInitUtil.initUpdateDomain(mapTagging, "标记删除");
        int r = mapTaggingMapper.updateByPrimaryKeySelective(mapTagging);
        return r;
    }

    
    
    
}
